import { useEffect, useMemo, useRef, useState } from "react";
import { Toast } from "antd-mobile";

const Index = () => {
    const MainRef = useRef(null)
    const user_id = 2
    const server_id = 4553
    const ws = useMemo(() => {
        return new WebSocket(
            `ws:133.44.139.133:8003/koa/ws?user_id=${user_id}&server_id${server_id}`
        )
    }, [])
    const [connectList, setConnectList] = useState([])
    useEffect(() => {
        ws.onopen = () => {
            console.log('连接成功');
            ws.send(JSON.stringify({ type: "getChatList" }))
        };
        ws.onmessage = (msg) => {
            const { type, message, data } = JSON.parse(msg.data)
            if (type === "getChatList") {
                console.log(data);
                setConnectList(data)
                Toast.show({
                    icon: "success",
                    content: message,
                    duration: 1000,
                })
            }
        }
    }, [])
    return <div>11111</div>;
};

export default Index;
